package com.santiao.youxiang.ui.adapter

import android.widget.CheckBox
import com.santiao.youxiang.bean.EmailBean
import com.santiao.youxiang.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.santiao.youxiang.utils.DemoUtils
import org.jsoup.Jsoup

//import com.santiao.youxiang.database.Bill

//import com.santiao.youxiang.database.yibaoBill

class EmailSelectAdapter(data: MutableList<EmailBean>? = null/*, type: Int*/) :
    BaseQuickAdapter<EmailBean, BaseViewHolder>(R.layout.item_email_select, data) {
//         var types =type

    init {
        addChildClickViewIds(R.id.ck_list) // 关键：声明子视图 ID
    }


    override fun convert(holder: BaseViewHolder, item: EmailBean) {
        // 绑定数据到视图
//        Log.e( "convert: ",types.toString())

        // 获取 CheckBox 并绑定选中状态
        val checkBox: CheckBox = holder.getView(R.id.ck_list)
        checkBox.isChecked = item.isChecked

        holder.setText(R.id.email_from_icon,item.fromName)
        holder.setText(R.id.email_subject,item.subject)
        holder.setText(R.id.email_from_name,item.fromName)
        holder.setText(R.id.email_time,DemoUtils.formatDate(item.time))


        val document = Jsoup.parse(item.content)
        val textContent = document.text()
        holder.setText(R.id.email_content,textContent)
//        holder.eContent.text=textContent
//        holder.itemView.setOnClickListener{
////            LZYLog.i("lzyemailget","${item.uid}")
//            val bundle=Bundle()
////            bundle.putInt("type", types)
//            bundle.putSerializable("email", item)
////            LZYBaseActivity.forward<EmailDetailActivity>(mContext,bundle)
//
//        }


    }

    fun toggleAll(selectAll: Boolean) {
        data?.forEach { it.isChecked = selectAll }
        notifyDataSetChanged() // 刷新整个列表
    }

}